var app = getApp();
var dateTimePicker = require('../../utils/dateTimePicker.js');
var date = new Date();
var currentYear = date.getFullYear();
var nextYear = currentYear + 1;

Page({

  data: {
    showgif:true,
    hArray: [
      {
        hou: 1,
        name: '白班'
      },
      {
        hou: 2,
        name: '夜班'
      }
    ],
    bname:'',
    btime:'',
    hindex: 0,
    rulerhou:'',
    hname:'请选择变更班次',
    date: '2018-10-01',
    time: '12:00',
    dateTimeArray2: null,
    dateTime2: null,
    dateTimeArray1: null,
    dateTime1: null,
    startYear: '',
    endYear: '',
    typename:'',
    status:'',
    statusindex:"",
    choose:'',
    info:{},
    startDate:'请选择开始时间',
    endDate:'请选择结束时间',
    pageInfo: '',
    index: 0,
    eindex: 0,
    index2: 0,
    array: [],
    earray: [],
    array2: ['上班', '下班'],
    date: '',
    liyou:'',
    workz:'',
    date2:'',
    hou:''
  },

  onLoad: function () {
    var that = this;
    if (!wx.getStorageSync('openid')) {
      app.error("请登录后再操作");
      return false;
    }
  },
  onShow:function(){
    this.getwork();
  },
//角色变更事件
bindPickerChange_hx(e) {
     console.log('picker发送选择改变，索引为', e.detail.value);
  　var hname = this.data.hArray[e.detail.value].name //根据索引去查对应的id
    if(e.detail.value == "0"){
      this.setData({   //给变量赋值
        bname: "白班时间",
        btime:"从6点-24点"
       })
    }else{
      this.setData({   //给变量赋值
        bname: "夜班时间",
        btime:"从18点-次日12点"
       })
    }

    this.setData({   //给变量赋值
        hindex: e.detail.value,
        hname:hname
  })
},
 
 

//时间控件end
  formSubmit: function (event) {
    var that = this;
    that.setData({showgif:true});
    wx.request({
      url: app.apiUrl + '/api/index/jswapplysb',
      data: {
        openid:wx.getStorageSync('openid'),
      },
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: res=> {
        that.setData({showgif:false});
        if(res.data.code == 0){
          wx.showModal({
            title: '温馨提示',
            content: res.data.msg,
            showCancel: false
          });
    
        }else{
          wx.showModal({
            title: '温馨提示',
            content: res.data.msg,
            showCancel: false
          }); 
          setTimeout(function(){
            wx.redirectTo({
              url: '/page/my/index',
            })
          },1500);
          

        }
         
      }
    })
  
  },
 

  getwork(){
    var that = this
  wx.request({
    url: app.apiUrl + '/api/index/jswbaninfo2',
    data: {
      openid:wx.getStorageSync('openid'),
      groupid: wx.getStorageSync('groupid'),
    },
    method: 'POST',
    header: { 'content-type': 'application/x-www-form-urlencoded' },
    success: res=> {
        that.setData({showgif:false});
        if(res.data){
          that.setData({ info: res.data.data});
          if(res.data.data.apply == "1"){
            that.setData({ hname:res.data.data.banci2});
          }
          that.setData({ btime:res.data.data.btime,bname:res.data.data.bname,typename:res.data.data.typename});
        }
    }
  })
},

  bindKeyInput(e){
      console.log(e.detail.value)
      this.setData({ liyou: e.detail.value});
  },

  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },

  ebindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      edate: e.detail.value
    })
  },


  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },

  ebindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      eindex: e.detail.value
    })
  },

})